<template>
	<view class="login">
		<form>
			<input type="text" v-model="userdata.email" placeholder="输入登陆邮箱" />
			<input type="password" v-model="userdata.password" value="" placeholder="请输入密码" />
			<button @click="subLogin" class="submit">提交</button>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userdata: {
					email: "",
					password: ""
				}
			}
		},
		methods: {
			subLogin() {
				let email = this.userdata.email.trim()
				console.log(email)
				var reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
				if (reg.test(email)) {
					if (this.userdata.password.trim().length > 4 && this.userdata.password.trim().length < 20) {
						this.$store.commit("setuserdata", this.userdata)
						console.log(this.$store.state.userdata)
						uni.switchTab({
							url: "../index/index"
						})
					} else {
						uni.showToast({
							title: "密码不正确",
							duration: 1000
						})
					}
				} else {
					uni.showToast({
						title: "邮箱格式不正确",
						duration: 1000
					})
				}
			}

		}
	}
</script>

<style lang="less" scoped>
	.login {
		width: 100vw;
		height: calc(100vh - 44px);
		display: flex;
		justify-content: center;
		align-items: center;

		form {
			width: 60vw;
			padding: 30px 20px;

			input {
				width: 100%;
				height: 40px;
				margin-bottom: 20px;
			}

			button {
				width: 120px;
				height: 40px;
				border-radius: 5px;
			}
		}
	}
</style>
